package com.lu.library.ext

import com.lu.library.http.ApiCoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

fun CoroutineScope.launchSafe(context: CoroutineContext = EmptyCoroutineContext,
                              start: CoroutineStart = CoroutineStart.DEFAULT,
                              block: suspend CoroutineScope.() -> Unit): Job {
    return launch(context+ApiCoroutineExceptionHandler(),start, block)
}